package com.example.Controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.dao.DepartmentMapper;
import com.example.pojo.Department;
import com.example.util.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "部门管理")
@CrossOrigin
@RestController
public class DepartmentController {
    @Autowired
    private DepartmentMapper departmentMapper;


    //查询部门信息
    @PostMapping("/selectAllDep")
    private Result selectAllDep(){
        List<Department> departments = departmentMapper.selectList(null);
        return new Result("200","部门信息获取成功",departments);
    }

    //修改部门信息
    @RequestMapping("/updateAllDep")
    private Result updateAllDep(@RequestBody Department department){
        Department department1 = new Department();
        QueryWrapper<Department> wrapper = new QueryWrapper<>();
        wrapper.eq("department_id",department.getDepartmentId());
        int update = departmentMapper.update(department1, wrapper);
        return new Result("200","修改部门成功",update);
    }

    //新增部门
    @RequestMapping("/addAllDe")
    private Result addAllDe(@RequestBody Department department){
        int insert = departmentMapper.insert(department);
        return new Result("200","添加部门成功",insert);
    }

    //删除部门
    @RequestMapping("/delectDe")
    private Result delectDe(@RequestBody Department department){
        QueryWrapper<Department> wrapper = new QueryWrapper<>();
        wrapper.eq("department_id",department.getDepartmentId());
        int insert = departmentMapper.delete(wrapper);
        return new Result("200","删除部门成功",insert);
    }
}
